﻿using AdminStystem.Domain;
using AdminSytem.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminSytem.Application.Login
{
    public class AdminService : IAdminService
    {
        private readonly IRepository<User> repository;
      

        public AdminService(IRepository<User> repository)
        {
            this.repository = repository;
        }
        public async  Task<ResultDto<User>> LoginQuery(string? UserName, string? UserPass)
        {
            ResultDto<User> result = new ResultDto<User>();
            var list = repository.GetAll().Where(x => x.UserName == UserName);
                if (list.Count() == 0)
            {
                result.StatusCode = StatusCode.Faield;
                result.Message = "用户名不存在！";

            }
            else
            {
                var entity = list.FirstOrDefault();
                if (entity.UserPassWord != UserPass)
                {
                    result.StatusCode = StatusCode.Faield;
                    result.Message = "用户名和密码不匹配！";
                }
                else
                {
                    result.StatusCode = StatusCode.Success;
                    result.Message = "登录成功！";
                    result.Data = entity;
                }
            }
            return result;

        }
    }
}
